package zozopo.manual;

import java.io.IOException;
import java.sql.Connection;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletResponseAware;

import zozopo.database.BusiDatabaseManager;
import zozopo.manual.operations.ReleaseOS;

import com.opensymphony.xwork2.ActionSupport;

public class BearAction extends ActionSupport implements ServletResponseAware{

	private HttpServletResponse response;
	private int id;
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String execute(){
		BusiDatabaseManager databaseConnection = new BusiDatabaseManager();
		Connection conn = databaseConnection.getConnection();
		
		ReleaseOS releaseOS = new ReleaseOS(conn);

		try {
			if(releaseOS.bear(id));
			response.getWriter().write(SUCCESS);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			try {
				response.getWriter().write(ERROR);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
		databaseConnection.releaseConnection(conn);
		
		return NONE;
	}

	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		response = arg0;
	}
}
